/**
 * Company : Thai Informatic System Co., Ltd.
 * Created By : Dr.Tree
 * Created On : Sep 22, 2012  12:14:01 PM 
 * e-Mail : chatree@tis.co.th
 * Mobile Phone : (+66) 087-921-5115
 * Package Name : jpa.service.promis.common
 * File Name : CostProjectZoneServices.java
 * TODO
 */
package jpa.service.promis.common;

import java.util.ArrayList;
import java.util.List;
import javax.persistence.EntityManager;
import org.apache.log4j.Logger;
import jpa.entitys.common.CommonEntity;
import jpa.entitys.promis.common.CostProjectZone;
import jpa.entitys.promis.common.CostProjectZonePK;
import jpa.service.common.JPAService;
import promis.utility.CommonService;

/**
 * @author chatree
 *
 */
public class CostProjectZoneServices extends JPAService {
	
	private static final Logger log = Logger.getLogger(CostProjectZoneServices.class);

	public CostProjectZoneServices(EntityManager em) {
		super(em);
	}
	
	public CostProjectZone FindByKey(CostProjectZonePK costBuildingPhasePk ) throws Exception 
	{					
		return super.ConvertToYoureObject(super.find(costBuildingPhasePk, "CostProjectZone.findById"));
	}
	
	public CostProjectZone InsertedOrUpdated(CostProjectZone vlaue) throws Exception {
		CostProjectZone obj = vlaue;
		try{		
			if(CommonService.IsNull(obj.getLastUpdOn()))
				super.inserted(obj);
			else
				super.updated(obj);
		}catch(Exception e)
		{
			log.error(e);
			throw e;
		}
		return obj;
	}
	
	public List<CostProjectZone> Inserted(List<CostProjectZone> vlauelist) throws Exception {		
		try{
			List<CommonEntity> common_lst = new ArrayList<CommonEntity>();			
			for(CostProjectZone obj : vlauelist) {
				common_lst.add(obj);
			}
			
			if(CommonService.getSize(common_lst) > 0)
				super.inserted(common_lst);
			
		}catch(Exception e)
		{
			log.error(e);
			throw e;
		}
		return vlauelist;
	}
	
	public List<CostProjectZone> Updated(List<CostProjectZone> vlauelist) throws Exception {
		try{
			List<CommonEntity> common_lst = new ArrayList<CommonEntity>();
			for(CostProjectZone obj : vlauelist){
				common_lst.add(obj);	
			}				
			
			if(CommonService.getSize(common_lst) > 0)
				super.updated(common_lst);
			
		}catch(Exception e)
		{
			log.error(e);
			throw e;
		}
		return vlauelist;
	}
}
